package com.mark.controller.backend;

import com.google.common.collect.Lists;
import com.mark.common.ServerResponse;
import com.mark.enums.UserStateEnum;
import com.mark.pojo.Admin;
import com.mark.pojo.Category;
import com.mark.service.ICategoryService;
import com.mark.util.AdminUtil;
import com.mark.vo.CategoryIndexVo;
import com.mark.vo.CategoryVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Mark on 2018/3/24.
 * 商品管理后台接口
 */
@Controller
@RequestMapping("/manage/category/")
public class CategoryManageController {
    @Autowired
    private ICategoryService iCategoryService;

    // TODO: 2018/3/25 一级商品类别的添加 
    //1.添加子类商品种类
    @RequestMapping("add_category")
    @ResponseBody
    public ServerResponse addCategory(HttpSession session,String categoryName,Integer parentId,String imageAddress){
        if(parentId == null ||StringUtils.isBlank(categoryName) || StringUtils.isBlank(imageAddress)){
            return ServerResponse.createByErrorMessage("添加失败！提交的数据有空值");
        }
        return iCategoryService.addCategory(categoryName,parentId,imageAddress);
    }

    //2.更新商品种类名
    @RequestMapping("update_category_name")
    @ResponseBody
    public ServerResponse updateCategoryName(HttpSession session,Integer categoryId,String CategoryNewName){
        return iCategoryService.updateCategoryName(categoryId,CategoryNewName);
    }


    @RequestMapping("get_category")
    @ResponseBody
    public ServerResponse<List<Category>> getChildrenParallelCategory(HttpSession session, @RequestParam(value = "categoryId" ,defaultValue = "0") Integer categoryId){
        return iCategoryService.getChildrenParallelCategory(categoryId);
    }

    @RequestMapping("get_deep_category.do")
    @ResponseBody
    public ServerResponse<List<Integer>> getCategoryAndDeepChildrenCategory(HttpSession session,@RequestParam(value = "categoryId" ,defaultValue = "0") Integer categoryId){
        return iCategoryService.selectCategoryAndChildrenById(categoryId);
    }


}
